package com.fate.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fate.framework.utils.CommonUtil;
import com.fate.framework.utils.SystemUtil;
import com.fate.system.dto.rolemenu.RoleMenuPageDTO;
import com.fate.system.entity.RoleMenu;
import com.fate.system.mapper.RoleMenuMapper;
import com.fate.system.service.IRoleMenuService;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * @author 47349
 * @description 针对表【sys_role_menu(角色菜单映射表)】的数据库操作Service实现
 * @createDate 2024-08-09 02:06:32
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu>
    implements IRoleMenuService {

  public Page<RoleMenu> getPageList(RoleMenuPageDTO pageDTO) {
    Page<RoleMenu> page = SystemUtil.buildPageFromDTO(pageDTO, RoleMenu.class);
    return this.lambdaQuery().orderByDesc(RoleMenu::getGmtCreate).page(page);
  }

  @Override
  public List<String> getMenuIdsByRoleIds(List<String> roleIds) {
    if (CommonUtil.notNullOrEmpty(roleIds)) {
      List<RoleMenu> roleMenuList = this.lambdaQuery().in(RoleMenu::getRoleId, roleIds).list();

      if (CommonUtil.notNullOrEmpty(roleMenuList)) {
        return roleMenuList.stream().map(RoleMenu::getMenuId).toList();
      }

      return List.of();
    }
    return List.of();
  }
}
